#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Author: '习惯'
# @Email: 'songbing513@gmail.com'
# @Date: '2025/9/3 22:54'
# @Project: 'McpAgent'
# @File: '03.py'
# @Software: 'PyCharm'


# token 追踪

from langchain_deepseek import ChatDeepSeek

llm = ChatDeepSeek(
    model="deepseek-chat",
    temperature=0,
    base_url="https://api.deepseek.com/v1",
    api_key="sk-3291e6df463f408eaeea2629bd84fc6a",
)

res = llm.invoke("你叫什么名字1")
print(res.usage_metadata)

# chatopenapi
from langchain_openai import ChatOpenAI

llm =  ChatOpenAI(
        model="deepseek-chat",
        temperature=0,
        base_url="https://api.deepseek.com/v1",
        api_key="sk-3291e6df463f408eaeea2629bd84fc6a"
)

res = llm.invoke("你叫什么名字2")
print(res.response_metadata["token_usage"])